package com.yyz.lease.web.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyz.lease.model.entity.ApartmentInfo;
import com.yyz.lease.model.entity.FacilityInfo;
import com.yyz.lease.model.entity.LabelInfo;
import com.yyz.lease.web.app.mapper.*;
import com.yyz.lease.web.app.service.ApartmentInfoService;
import com.yyz.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.yyz.lease.web.app.vo.apartment.ApartmentItemVo;
import com.yyz.lease.web.app.vo.graph.GraphVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 */
@Service
@RequiredArgsConstructor
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {
    private final LabelInfoMapper labelInfoMapper;
    private final GraphInfoMapper graphInfoMapper;
    private final RoomInfoMapper roomInfoMapper;
    private final FacilityInfoMapper facilityInfoMapper;

    /**
     * 根据id获取所属公寓信息
     */
    @Override
    public ApartmentItemVo getApartmentItemVoById(Long id) {
        //查询公寓信息
        ApartmentInfo apartmentInfo = getById(id);
        //查询标签信息
        List<LabelInfo> labelInfoList = labelInfoMapper.selectLabelInfosByApartmentId(id);
        //查询图片信息
        List<GraphVo> graphVoList = graphInfoMapper.selectGraphInfosByApartmentId(id);
        //查询房间最小租金
        BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(id);

        //拼接数据
        ApartmentItemVo apartmentItemVo = new ApartmentItemVo();
        BeanUtils.copyProperties(apartmentInfo, apartmentItemVo);
        apartmentItemVo.setGraphVoList(graphVoList);
        apartmentItemVo.setMinRent(minRent);
        apartmentItemVo.setLabelInfoList(labelInfoList);

        return apartmentItemVo;
    }

    @Override
    public ApartmentDetailVo getDetailById(Long id) {
        //查询公寓信息
        ApartmentInfo apartmentInfo = getById(id);
        //查询标签信息
        List<LabelInfo> labelInfoList = labelInfoMapper.selectLabelInfosByApartmentId(id);
        //查询图片信息
        List<GraphVo> graphVoList = graphInfoMapper.selectGraphInfosByApartmentId(id);
        //查询房间最小租金
        BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(id);
        //查询配套列表
        List<FacilityInfo> facilityInfoList = facilityInfoMapper.selectFacilityInfosByApartmentId(id);

        //拼接数据
        ApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();
        BeanUtils.copyProperties(apartmentInfo, apartmentDetailVo);
        apartmentDetailVo.setGraphVoList(graphVoList);
        apartmentDetailVo.setMinRent(minRent);
        apartmentDetailVo.setLabelInfoList(labelInfoList);
        apartmentDetailVo.setFacilityInfoList(facilityInfoList);

        return apartmentDetailVo;
    }
}




